package com.pucong.gitee.database.backup.business.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pucong.gitee.database.backup.business.sys.service.SysUserInfoService;
import com.pucong.gitee.database.backup.common.entity.sys.SysUserInfo;
import com.pucong.gitee.database.backup.common.entity.sys.dto.SysUserInfoSaveDto;
import com.pucong.gitee.database.backup.common.entity.sys.vo.SysUserInfoVo;
import com.pucong.gitee.database.backup.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author pucong
 * @company gitee.com/pucong
 * @create 2020-12-01
 */
@RestController
@RequestMapping("/sys/rmUserInfo")
@Api(value = "用户基础信息-API ",tags = "02. 用户管理")
public class SysUserInfoController {

    @Autowired
    private SysUserInfoService sysUserInfoService;

    @GetMapping("/getRmUserInfoListByPage/{pageNum}/{pageSize}")
    @ApiOperation(value = "01分页条件查询")
    public Res<IPage<SysUserInfo>> getRmUserInfoListByPage(@ApiParam(value = "页数",example = "1")@PathVariable("pageNum") int pageNum, @ApiParam(value = "一页大小",example = "10")@PathVariable("pageSize") int pageSize, SysUserInfo sysUserInfo){
        IPage rmUserInfoPageList = sysUserInfoService.getRmUserInfoListByPage(pageNum,pageSize, sysUserInfo);
        return Res.ok(rmUserInfoPageList);
    }

    @GetMapping("/getRmUserInfoById/{id}")
    @ApiOperation(value = "02根据用户id查询")
    public Res<SysUserInfoVo> getRmUserInfoById(@ApiParam("主键")@PathVariable("id") String id){
        SysUserInfoVo vo = sysUserInfoService.getRmUserInfoById(id);
        return Res.ok(vo);
    }

    @PostMapping("/insertRmUserInfo")
    @ApiOperation(value = "03新增")
    public Res<Integer> insertRmUserInfo(@Valid @RequestBody SysUserInfoSaveDto sysUserInfo){
        return Res.ok(sysUserInfoService.insertRmUserInfo(sysUserInfo));
    }

    @PutMapping("/updateRmUserInfoById/{id}")
    @ApiOperation(value = "04根据用户id更新数据")
    public Res<Integer> updateRmUserInfoById(@ApiParam("主键")@PathVariable("id") String id,@Valid @RequestBody SysUserInfoSaveDto sysUserInfoSaveDto){
        return Res.ok(sysUserInfoService.updateRmUserInfoById(id, sysUserInfoSaveDto));
    }

    @PutMapping("/restPwd/{id}")
    @ApiOperation(value = "05重置密码")
    public Res<Integer> restPwd(@ApiParam("用户id")@PathVariable("id") String id){
        return Res.ok(sysUserInfoService.restPwd(id));
    }

    @DeleteMapping("/deleteRmUserInfoById/{id}")
    @ApiOperation(value = "06根据用户id删除数据")
    public Res<Integer> deleteRmUserInfoById(@ApiParam("主键")@PathVariable("id") String id){
        return Res.ok(sysUserInfoService.deleteRmUserInfoById(id));
    }
}
